var models = require('../../models');
var mediaInfoGet = require('../../tool/mediaInfoGet.js');
module.exports = function (req, res) {
    var id = req.param('id');
    if (!id) {
        res.redirect('/');
    }
    console.log('id');
    var mediaModel = models['media'];
    var userFields = ['username', 'description', 'headpic', '_id'];
    var callback = function (err, doc) {
        if (err) {
            console.log(err);
            return;
        }
        res.locals = mediaInfoGet.mix(res.locals, mediaInfoGet);
        console.log(doc);
        res.render('media/media', {
            'data':doc
        }, 0);
    };
    var query = mediaModel.findById(id);
    query.populate('author', userFields.join(' '));
    query.exec(callback);
};